#pragma once

#include "widgets.h"
#include <QWidget>
#include <QColor>
#include <QMouseEvent>
#include <QCalendarWidget>
#include <QFrame>
#include <vector>

class QSpinBox;
class QMenu;

class S_WIDGETS_EXPORT SCalendar : public QCalendarWidget
{
	Q_OBJECT
public:
	SCalendar(QWidget* parent = nullptr);
	~SCalendar();
	void setStart(const QDate& start);
	void setEnd(const QDate& end);
	void setSelectedColorBetweenTwoDatas(QDate start, QDate end);

protected:
	void paintCell(QPainter* painter, const QRect& rect, const QDate& date) const override;
	bool eventFilter(QObject* obj, QEvent* event);

private:
	QDate _start;
	QDate _end;
	QDate _colorStart;
	QDate _colorEnd;
};

class DateSelected
{
public:
	std::vector<std::pair<QString, QDate>> dateSelected;
	int dateCountSelected() { return dateSelected.size(); };
	void clear() { dateSelected.clear(); };
};

class S_WIDGETS_EXPORT DualCalendars : public QFrame
{
	Q_OBJECT
public:
	explicit DualCalendars(QWidget* parent = nullptr);
	~DualCalendars();
	void setConnection();
	void setStartEndDate(QDate start,QDate end);
	void hideAfterSelected();
	SCalendar* getLeftSCalendar()	{ return calL;}
	SCalendar* getRightSCalendar()  { return calR; }

signals:
	void StartEndDatedSelected(int,int);

protected:
	bool eventFilter(QObject* obj, QEvent* event);
	void paintEvent(QPaintEvent*)override;

protected Q_SLOTS:
	void onrlClicked(std::pair<QString, QDate> info);
	void onMenuShow();
	void onMenuHide();

private:
	bool				isShow = false;
	bool				isMenuShow = false;
	SCalendar*			calL = nullptr;
	SCalendar*			calR = nullptr;
	DateSelected		selectedDate;
	QMenu*				calLmenu = nullptr;
	QMenu*				calRmenu = nullptr;
};
